<template>
  <div class="about">
    <div class="container py-5">
      <!-- 个人介绍区域 -->
      <section class="intro-section mb-5" data-aos="fade-up">
        <div class="intro-card card border-0 shadow-lg">
          <div class="card-body p-5">
            <div class="row align-items-center">
              <div class="col-lg-4 text-center mb-4 mb-lg-0" data-aos="fade-right">
                <div class="avatar-wrapper">
                  <img 
                    :src="require('@/assets/head.jpg')" 
                    alt="我的头像" 
                    class="img-fluid rounded-circle shadow-lg profile-avatar"
                    style="max-width: 250px; width: 100%;"
                  >
                  <div class="avatar-glow"></div>
                  <div class="floating-elements">
                    <div class="float-element" style="--delay: 0s; --x: 20px; --y: -30px;">💻</div>
                    <div class="float-element" style="--delay: 1s; --x: -25px; --y: 15px;">🚀</div>
                    <div class="float-element" style="--delay: 2s; --x: 30px; --y: 25px;">⚡</div>
                    <div class="float-element" style="--delay: 0.5s; --x: -20px; --y: -25px;">✨</div>
                  </div>
                </div>
              </div>
              <div class="col-lg-8" data-aos="fade-left">
                <h1 class="display-5 fw-bold text-primary mb-4 title-gradient">
                  关于我
                  <div class="title-underline"></div>
                </h1>
                <p class="lead mb-4 text-slide-in">
                  {{ personalInfo.introduction || '你好！我是一名热爱技术的全栈开发者...' }}
                </p>
                <p class="mb-4 text-slide-in" style="animation-delay: 0.2s;">
                  {{ personalInfo.description || '在这个博客中，我会分享我的技术经验...' }}
                </p>
                <div class="intro-stats mt-4" data-aos="fade-up" data-aos-delay="400">
                  <div class="row text-center">
                    <div class="col-4">
                      <div class="stat-box">
                        <h3 :class="`stat-number text-${personalInfo.stats?.experience?.color || 'primary'}`">
                          {{ personalInfo.stats?.experience?.value || '3+' }}
                        </h3>
                        <p class="stat-label">{{ personalInfo.stats?.experience?.label || '年经验' }}</p>
                      </div>
                    </div>
                    <div class="col-4">
                      <div class="stat-box">
                        <h3 :class="`stat-number text-${personalInfo.stats?.projects?.color || 'success'}`">
                          {{ personalInfo.stats?.projects?.value || '50+' }}
                        </h3>
                        <p class="stat-label">{{ personalInfo.stats?.projects?.label || '项目完成' }}</p>
                      </div>
                    </div>
                    <div class="col-4">
                      <div class="stat-box">
                        <h3 :class="`stat-number text-${personalInfo.stats?.technologies?.color || 'warning'}`">
                          {{ personalInfo.stats?.technologies?.value || '10+' }}
                        </h3>
                        <p class="stat-label">{{ personalInfo.stats?.technologies?.label || '技术栈' }}</p>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- 技能和专长 -->
      <section class="skills-section mb-5">
        <h2 class="text-center mb-5">技能与专长</h2>
        <div class="row g-4">
          <div class="col-md-6" v-for="skill in skills" :key="skill.id">
            <div class="card border-0 shadow-sm h-100">
              <div class="card-body">
                <h5 :class="`card-title text-${skill.color}`">
                  <i :class="`${skill.icon} me-2`"></i>{{ skill.title }}
                </h5>
                <div class="skill-tags mb-3">
                  <span 
                    v-for="tech in skill.technologies" 
                    :key="tech.name"
                    :class="`badge bg-${skill.color} me-2 mb-2 ${skill.color === 'warning' ? 'text-dark' : ''}`"
                  >
                    {{ tech.name }}
                  </span>
                </div>
                <p class="text-muted">
                  {{ skill.description }}
                </p>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- 学习历程 -->
      <section class="learning-journey-section mb-5">
        <h2 class="text-center mb-5">学习历程</h2>
        <div class="timeline">
          <div class="timeline-item" v-for="journey in learningJourney" :key="journey.id">
            <div :class="`timeline-marker bg-${journey.color}`"></div>
            <div class="timeline-content">
              <h5 class="fw-bold">{{ journey.title }}</h5>
              <p class="text-muted mb-2">{{ journey.period }}</p>
              <p>
                {{ journey.description }}
              </p>
            </div>
          </div>
        </div>
      </section>

      <!-- 个人兴趣 -->
      <section class="interests-section mb-5">
        <h2 class="text-center mb-5">兴趣爱好</h2>
        <div class="row g-4">
          <div class="col-lg-3 col-md-6" v-for="interest in interests" :key="interest.id">
            <div class="interest-card card h-100 border-0 shadow-sm text-center">
              <div class="card-body p-4">
                <div class="interest-icon mb-3">
                  <i :class="`${interest.icon} text-${interest.color}`" style="font-size: 3rem;"></i>
                </div>
                <h5 class="fw-bold">{{ interest.title }}</h5>
                <p class="text-muted small">
                  {{ interest.description }}
                </p>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- 个人项目 -->
      <section class="projects-section mb-5">
        <h2 class="text-center mb-5">个人项目</h2>
        <div class="row g-4">
          <div class="col-lg-6" v-for="project in projects" :key="project.id">
            <div class="project-card card border-0 shadow-sm">
              <div class="card-body p-4">
                <div class="d-flex align-items-center mb-3">
                  <div class="project-icon me-3">
                    <i :class="`${project.icon} text-${project.color}`" style="font-size: 2rem;"></i>
                  </div>
                  <div>
                    <h5 class="fw-bold mb-1">{{ project.title }}</h5>
                    <small class="text-muted">{{ project.subtitle }}</small>
                  </div>
                </div>
                <p class="text-muted mb-3">
                  {{ project.description }}
                </p>
                <div class="tech-stack">
                  <span 
                    v-for="tech in project.technologies" 
                    :key="tech.name"
                    :class="`badge bg-${tech.color} me-2 mb-2`"
                  >
                    {{ tech.name }}
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- 教育背景 -->
      <section class="education-section mb-5">
        <h2 class="text-center mb-5">教育背景</h2>
        <div class="row justify-content-center">
          <div class="col-lg-8">
            <div class="card border-0 shadow-sm">
              <div class="card-body text-center p-4">
                <i :class="`${education.icon} text-${education.color} mb-3`" style="font-size: 3rem;"></i>
                <h5 class="fw-bold">{{ education.degree }}</h5>
                <p class="text-muted mb-0">{{ education.university }} | {{ education.period }}</p>
                <p class="mt-3">
                  {{ education.description }}
                </p>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- 联系方式 -->
      <section class="contact-section">
        <div class="card border-0 shadow-sm bg-light">
          <div class="card-body text-center p-5">
            <h3 class="mb-4">{{ contact.title }}</h3>
            <p class="lead mb-4">
              {{ contact.subtitle }}
            </p>
            <div class="d-flex justify-content-center flex-wrap gap-3">
              <template v-for="method in contact.methods" :key="method.id">
                <a 
                  v-if="method.url.startsWith('mailto:') || method.url.startsWith('http')" 
                  :href="method.url" 
                  :class="`btn btn-${method.type}`"
                >
                  <i :class="`${method.icon} me-2`"></i>{{ method.title }}
                </a>
                <router-link 
                  v-else 
                  :to="method.url" 
                  :class="`btn btn-${method.type}`"
                >
                  <i :class="`${method.icon} me-2`"></i>{{ method.title }}
                </router-link>
              </template>
            </div>
          </div>
        </div>
      </section>
    </div>
  </div>
</template>

<script>
export default {
  name: 'About',
  data() {
    return {
      // API数据
      personalInfo: {
        name: '',
        title: '',
        avatar: '',
        introduction: '',
        description: '',
        stats: {}
      },
      skills: [],
      learningJourney: [],
      interests: [],
      projects: [],
      education: {},
      contact: {
        title: '',
        subtitle: '',
        methods: []
      },
      
      // 加载状态
      isLoading: true,
      apiError: null
    }
  },
  mounted() {
    this.loadAboutData()
  },
  methods: {
    async loadAboutData() {
      try {
        this.isLoading = true
        
        // 调用API获取关于我页面数据
        const response = await fetch('http://localhost:3001/api/about')
        
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`)
        }
        
        const result = await response.json()
        
        if (result.success && result.data) {
          // 更新页面数据
          this.personalInfo = result.data.personalInfo || {}
          this.skills = result.data.skills || []
          this.learningJourney = result.data.learningJourney || []
          this.interests = result.data.interests || []
          this.projects = result.data.projects || []
          this.education = result.data.education || {}
          this.contact = result.data.contact || {}
        } else {
          throw new Error(result.message || 'API返回数据格式错误')
        }
        
      } catch (error) {
        console.error('加载关于我页面数据失败:', error)
        this.apiError = error.message
        
        // 设置默认数据作为后备
        this.setDefaultData()
      } finally {
        this.isLoading = false
      }
    },
    
    setDefaultData() {
      // 后备数据，防止API调用失败
      this.personalInfo = {
        name: '博主',
        title: '热爱技术的全栈开发者',
        introduction: '你好！我是一名热爱技术的全栈开发者，专注于现代Web开发技术。',
        description: '在这个博客中，我会分享我的技术经验、学习心得以及对行业趋势的思考。',
        stats: {
          experience: { value: '3+', label: '年经验', color: 'primary' },
          projects: { value: '50+', label: '项目完成', color: 'success' },
          technologies: { value: '10+', label: '技术栈', color: 'warning' }
        }
      }
      
      this.skills = [
        {
          id: 'frontend',
          title: '前端开发',
          icon: 'bi-laptop',
          color: 'primary',
          description: '熟练掌握现代前端框架和工具',
          technologies: [
            { name: 'Vue.js' },
            { name: 'JavaScript' },
            { name: 'HTML5' }
          ]
        }
      ]
      
      this.learningJourney = [
        {
          id: 'current',
          title: '全栈开发探索期',
          period: '2025年至今',
          color: 'primary',
          description: '深入学习现代Web开发技术栈...'
        }
      ]
      
      this.interests = [
        {
          id: 'coding',
          title: '编程',
          icon: 'bi-code-slash',
          color: 'primary',
          description: '热爱编程和技术探索'
        }
      ]
      
      this.projects = [
        {
          id: 'blog',
          title: '个人博客系统',
          subtitle: 'Vue 3 + Bootstrap',
          icon: 'bi-journal-code',
          color: 'primary',
          description: '响应式个人博客系统',
          technologies: [
            { name: 'Vue 3', color: 'primary' }
          ]
        }
      ]
      
      this.education = {
        degree: '计算机科学与技术 学士学位',
        university: '某知名大学',
        period: '2021-2025年',
        icon: 'bi-mortarboard',
        color: 'primary',
        description: '系统学习计算机基础知识'
      }
      
      this.contact = {
        title: '让我们一起交流',
        subtitle: '如果你对技术有任何问题，或者想要合作交流，欢迎联系我！',
        methods: [
          {
            id: 'email',
            title: '发送邮件',
            icon: 'bi-envelope',
            type: 'primary',
            url: 'mailto:your-email@example.com'
          }
        ]
      }
    }
  }
}
</script>

<style scoped>
.about {
  animation: fadeIn 0.8s ease-out;
}

/* 个人介绍卡片 */
.intro-card {
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  transition: all 0.4s ease;
}

.intro-card:hover {
  background: rgba(255, 255, 255, 0.85);
  transform: translateY(-5px);
}

/* 头像相关样式 */
.avatar-wrapper {
  position: relative;
  display: inline-block;
}

.profile-avatar {
  transition: all 0.4s ease;
  position: relative;
  z-index: 2;
}

.profile-avatar:hover {
  transform: scale(1.05);
}

.avatar-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 280px;
  height: 280px;
  background: radial-gradient(circle, rgba(13, 110, 253, 0.2) 0%, transparent 70%);
  border-radius: 50%;
  animation: pulse-glow 3s ease-in-out infinite;
  z-index: 1;
}

@keyframes pulse-glow {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.8; }
  50% { transform: translate(-50%, -50%) scale(1.1); opacity: 0.4; }
}

/* 浮动元素 */
.floating-elements {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.float-element {
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 1.5rem;
  animation: float-around 4s ease-in-out infinite;
  animation-delay: var(--delay);
  transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y)));
}

@keyframes float-around {
  0%, 100% { transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(0deg); }
  25% { transform: translate(calc(-50% + var(--x) + 10px), calc(-50% + var(--y) - 10px)) rotate(90deg); }
  50% { transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(180deg); }
  75% { transform: translate(calc(-50% + var(--x) - 10px), calc(-50% + var(--y) + 10px)) rotate(270deg); }
}

/* 标题样式 */
.title-gradient {
  position: relative;
  background: linear-gradient(45deg, #0d6efd, #6f42c1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.title-underline {
  position: absolute;
  bottom: -10px;
  left: 0;
  width: 0;
  height: 4px;
  background: linear-gradient(45deg, #0d6efd, #6f42c1);
  border-radius: 2px;
  animation: expand-underline 2s ease-out 0.5s forwards;
}

@keyframes expand-underline {
  to { width: 100px; }
}

/* 文本滑入动画 */
.text-slide-in {
  opacity: 0;
  transform: translateX(-30px);
  animation: slide-in 0.8s ease-out 0.3s forwards;
}

@keyframes slide-in {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* 统计数据样式 */
.stat-box {
  padding: 1.5rem 1rem;
  background: rgba(255, 255, 255, 0.65);
  border-radius: 15px;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.stat-box:hover {
  background: rgba(255, 255, 255, 0.80);
  border-color: rgba(13, 110, 253, 0.3);
  transform: translateY(-5px);
}

.stat-number {
  font-size: 2rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
  animation: count-up 2s ease-out 1s;
}

.stat-label {
  color: #6c757d;
  font-size: 0.9rem;
  margin-bottom: 0;
}

@keyframes count-up {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

/* 技能卡片 */
.card {
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  transition: left 0.5s;
}

.card:hover::before {
  left: 100%;
}

.card:hover {
  transform: translateY(-10px) scale(1.02);
  box-shadow: 0 20px 40px rgba(0,0,0,0.15) !important;
  background: rgba(255, 255, 255, 0.85);
}

.skill-tags {
  line-height: 2.2;
}

.skill-tags .badge {
  transition: all 0.3s ease;
  margin: 0.2rem 0.1rem;
}

.skill-tags .badge:hover {
  transform: scale(1.1);
}

/* 时间线 */
.timeline {
  position: relative;
  padding-left: 2rem;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 1rem;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(to bottom, #0d6efd, #6f42c1);
  border-radius: 2px;
}

.timeline-item {
  position: relative;
  margin-bottom: 3rem;
  padding-left: 3rem;
  opacity: 0;
  transform: translateX(-30px);
  animation: timeline-slide-in 0.6s ease-out forwards;
}

.timeline-item:nth-child(1) { animation-delay: 0.2s; }
.timeline-item:nth-child(2) { animation-delay: 0.4s; }
.timeline-item:nth-child(3) { animation-delay: 0.6s; }

@keyframes timeline-slide-in {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.timeline-marker {
  position: absolute;
  left: -2.3rem;
  top: 0.5rem;
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  border: 3px solid white;
  background: linear-gradient(45deg, #0d6efd, #6f42c1);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.3);
  animation: marker-pulse 2s ease-in-out infinite;
}

@keyframes marker-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.3); }
  50% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(13, 110, 253, 0.2); }
}

.timeline-content {
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(15px);
  padding: 2rem;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  border: 1px solid rgba(255, 255, 255, 0.4);
  transition: all 0.3s ease;
}

.timeline-content:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 40px rgba(0,0,0,0.15);
}

/* FAQ项目 */
.faq-item {
  border-left: 3px solid rgba(13, 110, 253, 0.3);
  padding-left: 1.5rem;
  margin-bottom: 1.5rem;
  transition: all 0.3s ease;
  border-radius: 0 8px 8px 0;
  background: rgba(255, 255, 255, 0.35);
  padding: 1rem 1.5rem;
}

.faq-item:hover {
  border-left-color: #0d6efd;
  background: rgba(13, 110, 253, 0.05);
  transform: translateX(10px);
}

/* 兴趣爱好卡片 */
.interest-card {
  transition: all 0.3s ease;
  cursor: pointer;
}

.interest-card:hover {
  transform: translateY(-8px) scale(1.02);
  background: rgba(255, 255, 255, 0.90) !important;
}

.interest-icon {
  transition: all 0.3s ease;
}

.interest-card:hover .interest-icon i {
  transform: scale(1.2) rotate(5deg);
}

/* 项目卡片 */
.project-card {
  transition: all 0.4s ease;
  cursor: pointer;
}

.project-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 15px 35px rgba(0,0,0,0.15) !important;
  background: rgba(255, 255, 255, 0.90) !important;
}

.project-icon {
  transition: all 0.3s ease;
}

.project-card:hover .project-icon i {
  transform: scale(1.1);
  animation: bounce 0.6s ease-in-out;
}

@keyframes bounce {
  0%, 20%, 60%, 100% { transform: translateY(0) scale(1.1); }
  40% { transform: translateY(-10px) scale(1.1); }
  80% { transform: translateY(-5px) scale(1.1); }
}

.tech-stack .badge {
  transition: all 0.3s ease;
}

.tech-stack .badge:hover {
  transform: scale(1.05);
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}

/* 联系卡片 */
.contact-section .card {
  background: linear-gradient(135deg, rgba(13, 110, 253, 0.15), rgba(255, 255, 255, 0.75));
}

/* 响应式调整 */
@media (max-width: 768px) {
  .avatar-glow {
    width: 220px;
    height: 220px;
  }
  
  .float-element {
    font-size: 1.2rem;
  }
  
  .stat-number {
    font-size: 1.5rem;
  }
  
  .timeline {
    padding-left: 1.5rem;
  }
  
  .timeline-item {
    padding-left: 2rem;
  }
  
  .timeline-marker {
    left: -1.8rem;
  }
}

/* 加载动画 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 深色主题支持 */
@media (prefers-color-scheme: dark) {
  .intro-card {
    background: rgba(33, 37, 41, 0.95);
  }
  
  .stat-box {
    background: rgba(55, 58, 60, 0.8);
  }
  
  .timeline-content {
    background: rgba(33, 37, 41, 0.95);
  }
}
</style>
